package com.znyj.cloud.device.util;

import org.apache.log4j.Logger;


import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by gaoliwei on 15-1-13.
 */
public class LocalInfoUtil {

    private static final Logger logger = Logger.getLogger(LocalInfoUtil.class);

    private static String IP = "127.0.0.1";

    private static String SERVER = null;

    private static boolean isOnline = false;

    private static List<String> onlineIpList = new ArrayList<>(Arrays.asList(""));

    static {
        try {
            InetAddress address = InetAddress.getLocalHost();
            IP = address.getHostAddress();
            isOnline = onlineIpList.contains(IP);
        } catch (UnknownHostException e) {
            logger.error("get ip exception " + IP);
        }
        SERVER = IP + ":" + "9977";
    }

    public static String getIP() {
        return IP;
    }

    public static String getLocalHost() {
        //return "172.28.235.21:8080";
        return SERVER;
    }

    public static boolean isOnline() {
        return isOnline;
    }


    public static void main(String[] args) {
        System.out.println(LocalInfoUtil.getIP());
        System.out.println(LocalInfoUtil.getLocalHost());
        System.out.println(LocalInfoUtil.isOnline());
    }
}
